﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MachiningHelper.ToolFile
{
    public class Content
    {
        public int ID { get; set; }
        public string Body { get; set; }
        public override string ToString()
        {
            return Body;
        }
        public static Content myContent(string Line)
        {
            string[] pars = Line.Split('|');
            int id;
            if (int.TryParse(pars[0], out id))
                return new Content { ID = id, Body = Line.Remove(0, pars[0].Length + 1) };
            else
                return new Content { ID = -1, Body = Line };

            //Content content = new Content();
            //if (Line.Length > 1 && Line.IndexOf("|") > -1)
            //{
            //    content.ID = int.Parse(Line.Substring(0, Line.IndexOf("|")));
            //    content.Body = Line.Substring(Line.IndexOf("|") + 1);
            //}
            //else if (Line.Length == 0)
            //{
            //    content.ID = -1;
            //    content.Body = null;
            //}
            //else
            //{
            //    content.ID = -1;
            //    content.Body = Line;
            //}
            //return content;
        }
        public static bool IsErrorOrNull(Content c)
        {
            if (c.Body == "[error]" | string.IsNullOrEmpty(c.Body))
                return true;
            return false;
        }
        public static bool IsError(Content c)
        {
            if (c.Body == "[error]")
                return true;
            return false;
        }
        public static bool IsSide1(Content c)
        {
            if (c.Body.Contains("NAME=SIDE,VALUE=1"))
                return true;
            return false;
        }
        public static bool IsSide2(Content c)
        {
            if (c.Body.Contains("NAME=SIDE,VALUE=2"))
                return true;
            return false;
        }
        public static bool IsSide3(Content c)
        {
            if (c.Body.Contains("NAME=SIDE,VALUE=3"))
                return true;
            return false;
        }
        public static bool IsSide4(Content c)
        {
            if (c.Body.Contains("NAME=SIDE,VALUE=4"))
                return true;
            return false;
        }
        public static bool IsCuststr(Content c)
        {
            if (c.Body.Contains("CUSTSTR=") | c.Body.Contains("PAN=CUSTSTR"))
                return true;
            return false;
        }
        public static bool IsCRN(Content c)
        {
            if (c.Body.Contains("NAME=CRN"))
                return true;
            return false;
        }
        public static bool IsLPZ(Content c)
        {
            if (c.Body.Contains("LPZ="))
                return true;
            return false;
        }
        public static bool IsWait(Content c)
        {
            if (c.Body.Contains("NAME=WAIT"))
                return true;
            return false;
        }
    }
}
